﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Runda.EShop.Common.Utility;
using Runda.EShop.Bll;

namespace Runda.EShop.SaaS.CustomerManage
{
    public partial class MessageList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid(ConstHelper.PAGE_INIT_INDEX);
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid(AspNetPager1.CurrentPageIndex - 1);
        }

        protected void gvCustomerList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink lnkReply = e.Row.FindControl("lnkReply") as HyperLink;
                DataRowView dv = e.Row.DataItem as DataRowView;
                if (dv["AnswerBy"] != DBNull.Value)
                {
                    lnkReply.Text = "修改";
                    lnkReply.NavigateUrl = "MessageAdd.aspx?MsgID="+dv["MessageID"].ToString();
                }
                else
                {
                    lnkReply.Text = "回复";
                    lnkReply.NavigateUrl = "MessageAdd.aspx?MsgID=" + dv["MessageID"].ToString();
                }
            }
        }
        private void BindGrid(int PageIndex)
        {
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            SqlDbParameter parm = null;
            //if (!string.IsNullOrEmpty(txtCustomerName.Text))
            //{
            //    parm = new SqlDbParameter();
            //    parm.ColumnName = "[CustomerName]";
            //    parm.ColumnType = DbType.String;
            //    parm.ParameterName = "@CustomerName";
            //    parm.ParameterValue = txtCustomerName.Text;
            //    parm.QualificationType = SqlDbParameter.QualificationSymbol.Like;
            //    parms.Add(parm);
            //}

            //if (!string.IsNullOrEmpty(txtCustomerCode.Text))
            //{
            //    parm = new SqlDbParameter();
            //    parm.ColumnName = "[CustomerCode]";
            //    parm.ColumnType = DbType.String;
            //    parm.ParameterName = "@CustomerCode";
            //    parm.ParameterValue = txtCustomerCode.Text;
            //    parm.QualificationType = SqlDbParameter.QualificationSymbol.Like;
            //    parms.Add(parm);
            //}

            int RecordCount = 0;
            DataTable list = new BizCustomerQABll().LoadCustomerMessageNonAnswer(parms, " CreatedAt DESC", AspNetPager1.PageSize, PageIndex, out RecordCount);

            gvCustomerList.DataSource = list;
            gvCustomerList.DataBind();

            AspNetPager1.RecordCount = RecordCount;
        }
    }
}